<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title> 变色 </title>
		<style>
			#div{
				width: 200px;
				height: 200px;
				border: 2px solid black;
			}
		</style>
	</head>
	<body>
		<p>
			<h4>点击下面框框：红绿交替</h4>
		</p>
		
		<div id="div"onclick="change()"></div>
		<script>
			function change(){
				var bg =document.getElementById('div');
				bg.style.backgroundColor=
				(bg.style.backgroundColor=='red'?'green':'red');
			}
		</script>
	</body>
</html>
